import { getSuppliers } from '@/api/BasicData/suppliers'
import { getUnits } from '@/api/BasicData/units'
import { getCategory } from '@/api/BasicData/category'
import { GoodsAPI } from '@/api/BasicData/goods'
import { ORDER_STATUS } from '@/constants/ORDER_STATUS'

export default {
  namespaced: true,
  state: {
    suppliers: [],
    products: [],
    units: [],
    categories: [],
    ORDER_STATUS
  },
  mutations: {
    SET_SUPPLIERS(state, suppliers) {
      state.suppliers = suppliers
    },
    SET_PRODUCTS(state, products) {
      state.products = products
    },
    SET_UNITS(state, units) {
      state.units = units
    },
    SET_CATEGORIES(state, categories) {
      state.categories = categories
    }
  },
  actions: {
    async fetchSuppliers({ commit }) {
      const data = (await getSuppliers({ page_size: 10000 })).results
      commit('SET_SUPPLIERS', data)
    },
    async fetchProducts({ commit }) {
      const data = (await GoodsAPI({ page_size: 10000 })).results
      commit('SET_PRODUCTS', data)
    },
    async fetchUnits({ commit }) {
      const data = this.units = (await getUnits({ page_size: 10000 })).results
      commit('SET_UNITS', data)
    },
    async fetchCategories({ commit }) {
      const data = (await getCategory({ page_size: 10000 })).results
      commit('SET_CATEGORIES', data)
    }
  }
}
